#include <iostream>
#include <vector>
using namespace std;

int search(vector<int> numbers, int x){
    int min=0;
    int max=numbers.size()-1;
    int position=-1;
    int positionless=min;
    while (min<=max){//先尝试找到x，若找不到，则记录比x小的位置，之后增加即可
        int mid=(min+max)/2;
        if (numbers[mid]==x){
            position=mid;
            break;
        }
        if (numbers[mid]<x){
            min=mid+1;
            positionless=min;
        } else {
            max=mid-1;
        }
    }
    while (position!=-1&&numbers[position-1]==x){
        position--;
    }
    while (position==-1&&positionless<numbers.size()){
        if (numbers[positionless]>=x){
            position=positionless;
            break;
        }
        positionless++;
    }
    return position;
}

int main(){
    std::vector<int> numbers={-1,2,3,3,3,4,5,6,7,8};
    int x=3;
    int position=search(numbers,x);
    printf("%d",position);
    return 0;
}